package game;

public class Vector {
	protected int x1;
	protected int x2;
	protected int y1;
	protected int y2;
	
	public Vector(int x1, int y1, int x2, int y2){
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	public float calculateXatY(int y){
		return distanceToY(y) * (x2-x1)+x1;
	}
	
	public float calculateYatX(int x){
		return distanceToX(x) * (y2-y1)+y1;
	}
	
	public boolean withinXBounds(int x){
		return (x >= x1 && x <= x2) || (x <= x1 && x >= x2);
	}
	
	public boolean withinYBounds(int y){
		return (y >= y1 && y <= y2) || (y <= y1 && y >= y2);
	}
	
	public float distanceToX(int x){
		return (float)Math.abs(x-x1)/Math.abs(x2-x1);
	}
	
	public float distanceToY(int y){
		return (float)Math.abs(y-y1)/Math.abs(y2-y1);
	}
}
